<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input
        style="width: 200px;"
        class="filter-item"
        placeholder="用户姓名"
        v-model="queryForm.realName"
      ></el-input>
      <el-input
        style="width: 200px;"
        class="filter-item"
        placeholder="参标编号"
        v-model="queryForm.markCode"
      ></el-input>
      <el-input
        style="width: 200px;"
        class="filter-item"
        placeholder="广告竞标编号"
        v-model="queryForm.voucherCode"
      ></el-input>
      <el-select
        clearable
        style="width: 170px"
        class="filter-item"
        v-model="queryForm.status"
        placeholder="请选择参与状态"
      >
        <el-option
          v-for="(val, key) in Dicts.MARK_JOIN_RECORD_STATUS"
          :key="key"
          :label="val"
          :value="key"
        ></el-option>
      </el-select>
      <el-button
        class="filter-item"
        @click="doQuery"
        type="primary"
        icon="el-icon-search"
        >查询</el-button
      >
    </div>
    <el-table v-loading="loading" :data="records" style="width: 100%">
      <el-table-column prop="rowId" label="ID" width="60"> </el-table-column>
      <el-table-column prop="realName" label="用户姓名" width="100">
      </el-table-column>
      <el-table-column prop="markCode" label="广告竞标编号" width="200">
      </el-table-column>
      <el-table-column prop="voucherCode" label="参标编号" width="200">
      </el-table-column>
      <el-table-column prop="title" label="广告标题" width="150">
      </el-table-column>
      <el-table-column prop="joinTime" label="参与时间" width="150">
      </el-table-column>
      <el-table-column prop="winTime" label="中标时间" width="150">
      </el-table-column>
      <el-table-column prop="outTime" label="出局时间" width="150">
      </el-table-column>
      <el-table-column prop="lastPayAmount" label="最后出价" width="100">
        <template slot-scope="scope">
          {{ `￥${scope.row.lastPayAmount}` }}
        </template>
      </el-table-column>
      <el-table-column prop="recordValue" label="参与状态" width="90">
      </el-table-column>
      <el-table-column prop="markValue" label="竞价标状态" width="90">
      </el-table-column>
      <el-table-column align="center" label="操作" class-name="small-padding">
        <template slot-scope="scope">
          <el-button
            size="mini"
            @click="detailAdBidMarkJoinRecord(scope.row)"
            title="详情"
            icon="el-icon-search"
            circle
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryForm.current"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="queryForm.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="queryForm.total"
      >
      </el-pagination>
    </div>

    <!-- 详情 -->
    <el-dialog
      :title="详情"
      :visible.sync="detailsDialogFormVisible"
      width="46%"
    >
      <el-form :model="showForm" label-width="140px" ref="showForm">
        <el-row>
          <el-col :span="20">
            <el-form-item label="广告标题:" prop="title">
              {{ `${showForm.title}` }}
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="10">
            <el-form-item label="用户姓名:" prop="realName">
              {{ `${showForm.realName}` }}
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="参与状态:" prop="recordValue">
              {{ `${showForm.recordValue}` }}
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="10">
            <el-form-item label="最后出价:" prop="lastPayAmount">
              {{ `${showForm.lastPayAmount}` }}
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="标状态:" prop="markValue">
              {{ `${showForm.markValue}` }}
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="10">
            <el-form-item label="竞价标编号:" prop="voucherCode">
              {{ `${showForm.voucherCode}` }}
            </el-form-item>
          </el-col>

          <el-col :span="10">
            <el-form-item label="参标编号:" prop="markCode">
              {{ `${showForm.markCode}` }}
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="10">
            <el-form-item label="参与时间:" prop="joinTime">
              {{ `${showForm.joinTime}` }}
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item
              label="中标时间:"
              v-if="showForm.status == 1 ? true : false"
              prop="winTime"
            >
              {{ `${showForm.winTime}` }}
            </el-form-item>

            <el-form-item
              label="出局时间:"
              v-if="showForm.status == 0 ? true : false"
              prop="outTime"
            >
              {{ `${showForm.outTime}` }}
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="20">
            <el-form-item label="广告图片:" prop="photo">
              <template slot-scope="scope">
                <img
                  :src="$oss(showForm.photo)"
                  alt
                  style="width: 280px;height: 170px"
                />
              </template>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { queryAdBidMarkJoinRecord } from '@/api/ad'

export default {
  name: 'adBidMarkJoinRecord',
  data() {
    return {
      checkDialogFormVisible: false,
      detailsDialogFormVisible: false,
      loading: false,
      queryForm: {
        current: 1,
        pages: 0,
        total: 0,
        size: 10,
        title: undefined
      },
      showForm: {},
      records: []
    }
  },
  created() {
    // 初始化一次oss client,如果初始化过一次返回上一次初始化对象
    this.initOssClient().then(_ => {
      this.doQuery()
    })
  },
  methods: {
    handleCurrentChange(current) {
      this.queryForm.current = current
      this.doQuery()
    },
    handleSizeChange(size) {
      this.queryForm.size = size
      this.doQuery()
    },
    doQuery() {
      this.loading = true
      queryAdBidMarkJoinRecord(this.queryForm).then(({ data: { data } }) => {
        this.queryForm.current = data.current
        this.queryForm.pages = data.pages
        this.queryForm.total = data.total
        this.queryForm.size = data.size
        this.records = data.records
        this.loading = false
      })
    },
    detailAdBidMarkJoinRecord(row) {
      this.detailsDialogFormVisible = true
      this.showForm = {
        realName: row.realName,
        photo: row.photo,
        title: row.title,
        markCode: row.markCode,
        recordValue: row.recordValue,
        markValue: row.markValue,
        joinTime: row.joinTime,
        winTime: row.winTime,
        outTime: row.outTime,
        lastPayAmount: row.lastPayAmount,
        status: row.status,
        voucherCode: row.voucherCode
      }
    }
  },
  components: {}
}
</script>

<style scoped></style>
